ffempg 视频分割和图片拼接 |
您所在的位置:网站首页 › ffmpeg 图像处理 › ffempg 视频分割和图片拼接 |
神奇的传送门:
先上一个高大上的大官网;这里是命令行的使用http://ffmpeg.org/documentation.htmlpython 版本的使用https://github.com/kkroening/ffmpeg-python参考了下面大神博客,传送门:https://blog.csdn.net/qq_36688143/article/details/79162121
参数操作
用 -r 参数设置帧率 (fps 每秒传输帧数(Frames Per Second)) ffmpeg –i input –r fps output有人说-r有时候会造成视频帧的缺失,这个时候尝试把-r 换成-framerate 参数-r写在 -i之前和之后有不同的含义,官网阐述: Set input frame rate with the -framerate input option (before -i). The default for reading inputs is -framerate 25 which will be set if no -framerate is specified.如果写在-i之前,那么 -r n 代表一秒送进去几张图片,默认为25张;The output frame rate for the video stream by setting -r after -i or by using the fps filter. If you want the input and output frame rates to be the same, then just declare an input -framerate and the output will inherit the same value (meaning you can omit the -r).如果写在-i之后,那么 -r n 代表一秒播几张图片,比如-r 5 -i input -r 30 代表一秒从input 读进来5张,但是生成视频一秒钟30张,也就是说每6张是一样的,如果不指定后面那么和前面保持一致; 一些常用的操作 提取关键帧:#要新建好output->之后的目录,将data/ad_hd.mp4 视频切分成关键帧 扔到output...中; ffmpeg -i data/ad_hd.mp4 -q:v 2 -vf select="eq(pict_type\,PICT_TYPE_I)" -vsync 0 output/test_ad_hd/frame%03d.jpgffmpeg -i inputfile.avi -r 1 -f image2 image-%05d.jpeg -r 指定抽取的帧率,即从视频中每秒钟抽取图片的数量。1代表每秒抽取一帧。 -f 指定保存图片使用的格式,可忽略。 image-%05d.jpeg,指定文件的输出名字。 #提取音频 ffmpeg -i inputpath/filename.mp4 -threads 1 -preset veryfast -max_muxing_queue_size 1024 -loglevel warning -f wav -ar 6000 filename.mp3 ffmpeg -i ad_hd.avi -q:a 0 -map a sample.mp3 # Extract audio#合并图片音频成为视频 ffmpeg -i output/frame_%d.jpg -i data/trailer.mp3 -acodec libvo_aacenc -vcodec libx264 merged.mp4 # Merge frame & audio #合并图片为视频 ffmpeg -i ./data/cat-girl/%05d.jpg -vcodec mpeg4 -r 30 testavi.avi 其中,-vcodec mpeg4 是指生成封装的文件,.avi可以改成.mp4 若报错 Could find no file with path ‘img/frames_%05d.jpg’ and index in the range 0-4 这是因为ffmpeg默认图片编号是从0开始的。即如果找不到frames_00000.jpg,则报错。 修改方式为 ffmpeg -start_number 345 -i img/frames_%05d.jpg -vcodec mpeg4 test.avi指定开始读取的图片编号。 注意:ffmpeg读取的时候会顺序读取,若出现编号中断,视频会就此结束。 还可以通过 -r 设置帧率。即每秒截取或集成几帧图片。 -y 若输出文件名冲突,直接覆盖。 更高级一点,我们怎么指定视频的大小呢, 3.2 预定义的视频尺寸下面两条命令有相同效果 ffmpeg -i input.avi -s 640x480 output.avi ffmpeg -i input.avi -s vga output.aviScale filter调整分辨率 ,Scale filter的优点是可以使用一些额外的参数 语法: Scale=width:height[:interl={1|-1}] 下面两条命令有相同效果 ffmpeg -i input.mpg -s 320x240 output.mp4 ffmpeg -i input.mpg -vf scale=320:240 output.mp4对输入视频成比例缩放 改变为源视频一半大小 ffmpeg -i input.mpg -vf scale=iw/2:ih/2 output.mp4 改变为原视频的90%大小 ffmpeg -i input.mpg -vf scale=iw*0.9:ih*0.9 output.mp4在未知视频的分辨率时,保证调整的分辨率与源视频有相同的横纵比。 例如宽度固定400,高度成比例: ffmpeg -i input.avi -vf scale=400:400/a ffmpeg -i input.avi -vf scale=400:-1 相反地,高度固定300,宽度成比例: ffmpeg -i input.avi -vf scale=-1:300 ffmpeg -i input.avi -vf scale=300*a:300
|
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |